package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.page.PageBeen;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.TbSellerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("seller")
public class TbSellerController {
    @Reference
    private TbSellerService tbSellerService;

    @RequestMapping("getSeller")
    @ResponseBody
    public Result getSeller(String name, String nickName, String status,
                            @RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "3") Integer pageSize) {

        try {
            PageBeen<TbSeller> pageBeen = tbSellerService.selectSeller(name, nickName, status, pageNum, pageSize);
            return Result.response(ResultEnum.SUCCESS).setData(pageBeen);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.response(ResultEnum.SUCCESS).setData(e);
        }
    }

    @RequestMapping("toUpdate/{sellerId}")
    @ResponseBody
    public Result toUpdate(@PathVariable("sellerId") String sellerId) {
        try {
            TbSeller tbSeller = tbSellerService.toUpdate(sellerId);
            return Result.response(ResultEnum.SUCCESS).setData(tbSeller);
        } catch (Exception e) {
            TbSeller tbSeller = tbSellerService.toUpdate(sellerId);
            return Result.response(ResultEnum.ERROR).setData(tbSeller);
        }

    }

    @RequestMapping("pass")
    @ResponseBody
    public Result pass(String sellerId) {

        String status = "2";
        int i = tbSellerService.update(sellerId, status);
        return Result.response(ResultEnum.SUCCESS);
    }

    @RequestMapping("noPass")
    @ResponseBody
    public Result noPass(String sellerId) {

        String status = "0";
        int i = tbSellerService.update(sellerId, status);
        return Result.response(ResultEnum.SUCCESS);
    }
}
